/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#include "StdAfx.h"
#include "MSTPDecoder.h"

//---------------------------------------------------------------------------

MSTPDecoder::MSTPDecoder(void)
{
}

MSTPDecoder::~MSTPDecoder(void)
{
}

//---------------------------------------------------------------------------

CString MSTPDecoder::GetMessageTypeName(MSTPPacket* packIn)
{
	CString str;

	if(packIn==NULL){
		str.Empty();
		return str;
	}

	switch(packIn->MessageType){
		case 0x00 :
			str = _T("Configuration");
			break;

		case 0x80 :
			str = _T("TCN");
			break;

		default :
			str = _T("- unknown -");
	}

	return str;
}

//---------------------------------------------------------------------------

CString MSTPDecoder::GetFlagsName(MSTPPacket* packIn)
{
	CString str;

	if(packIn==NULL){
		str.Empty();
		return str;
	}

	if(packIn->Flags==0){
		str = _T("-");
		return str;
	}

	str.Empty();
	if(packIn->Flags & 0x01){
		if(!str.IsEmpty()) str += _T(", ");
		str += _T("Topology change");
	}
	if(packIn->Flags & 0x80){
		if(!str.IsEmpty()) str += _T(", ");
		str += _T("Topology change acknowledge");
	}
	if(packIn->Flags & 0x7E){
		if(!str.IsEmpty()) str += _T(", ");
		str += _T("unknown flags");
	}

	return str;
}

//---------------------------------------------------------------------------

CString MSTPDecoder::FormatPriorityRaw(WORD wIn)
{
	CString str;

	str.Format(_T("%u"), wIn);
	return str;
}

CString MSTPDecoder::FormatPriorityAsCisco(WORD wIn)
{
	CString str;
	WORD wPriority, wSysId;

	wPriority = wIn & 0xFC00;
	wSysId    = wIn & 0x03FF;
	str.Format(_T("%u sys-id-ext %u"), wPriority, wSysId);
	return str;
}

//---------------------------------------------------------------------------
